import sys
from PyQt5.QtWidgets import QApplication, QMainWindow

import toolwindow  # 填写导入的py文件名
import index
from PyQt5.Qt import QIcon
from rich.console import Console  # 控制台模块
console = Console(color_system='auto')  # 创建控制台


def main_p():
    '''
    使用预设置文件抽取
    '''
    try:
        if ui.spinBox_Num.isEnabled() == False:
            index.main('/p', 'Y', None)
        else:
            Num = ui.spinBox_Num.value()
            index.main('/p', 'Y', Num)
    except:
        console.print_exception()


def main_c():
    '''
    创建新预设置文件
    '''
    try:
        filepath = None
        index.main('/c', None, None)
    except:
        console.print_exception()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    MainWindow = QMainWindow()
    ui = toolwindow.Ui_MainWindow()  # 填写导入的py文件名以及内部类名
    ui.setupUi(MainWindow)
    MainWindow.setWindowTitle('Slime辅助窗口')
    MainWindow.setWindowIcon(QIcon("./icon/Toolbox_Slime.jpg"))  # 设置窗口左上图标
    MainWindow.setStyleSheet(
        "#MainWindow{border-image:url(./icon/组件用背景5.jpg)}")  # 设置窗口背景

    MainWindow.show()

    ui.toolButton_p.clicked.connect(main_p)
    ui.toolButton_c.clicked.connect(main_c)

    sys.exit(app.exec_())
